%% Function to be used in the cablibration of the model for 2010
function f = calibration2010(parameter_vector0, alphaS, cSbar, cAbar, beta, gamE, etaE, xiH0_F, xiH0_C, xiH1_F, xiH1_C, varphi, alphaA, tau_F_income,gam, tau_R, tau_C, tau_1_F, Pop_data,pi_E,EE_set,HousingCostOption,NE,Nxr,Nxn,paramsR,paramsF,paramsC,xr,xn,Xn,Xr,XrXr,XnXn,frn_e);

tau_F=parameter_vector0(1);
XA=parameter_vector0(2);
XS=parameter_vector0(3);
XM=parameter_vector0(4);
parameter_vector_all = [alphaS, cSbar, cAbar, beta, gamE, etaE, tau_F, xiH0_F, xiH0_C, XA, XS, XM, xiH1_F, xiH1_C, varphi, alphaA, tau_F_income,gam, tau_R, tau_C, tau_1_F];

equilibrium = EquilibriumFunction(parameter_vector_all,Pop_data,pi_E,EE_set,HousingCostOption,NE,Nxr,Nxn,paramsR,paramsF,paramsC,xr,xn,Xn,Xr,XrXr,XnXn,frn_e);

VA_A = equilibrium(16);
VA_S = equilibrium(19);
VA_M = equilibrium(20);
l_A = equilibrium(30);  
l_S = equilibrium(28);
l_M = equilibrium(29);
pop_R = equilibrium(31);
pop_F = equilibrium(32);
pop_C = equilibrium(33);
EE_R = equilibrium(34);
EE_U = equilibrium(37);
pi_E_R(1) = equilibrium(42);
pi_E_R(2) = equilibrium(43);
pi_E_R(3) = equilibrium(44);
pi_E_R(4) = equilibrium(45);
pi_E_R(5) = equilibrium(46);
pi_E_U(1) = equilibrium(57);
pi_E_U(2) = equilibrium(58);
pi_E_U(3) = equilibrium(59);
pi_E_U(4) = equilibrium(60);
pi_E_U(5) = equilibrium(61);
pi_E_future(1) = equilibrium(62);
pi_E_future(2) = equilibrium(63);
pi_E_future(3) = equilibrium(64);
pi_E_future(4) = equilibrium(65);
pi_E_future(5) = equilibrium(66);


Dist_VA = sum(([VA_A,VA_S, VA_M]/100-[4.1158,13.3174,82.5669]/100).^2);


Dist_Emp = sum(( [l_A,l_S,l_M]-[12.85, 16.69, 70.46]/100).^2);

      
Dist_pop_2010 = sum(([pop_R, pop_F, pop_C ]-[13.68, 18.99, 67.33 ]/100).^2);


Dist_AverageEduc_RU_2010 = sum(([EE_R,EE_U]-[3.8094,7.4188]).^2);


Dist_EducGroups_R = sum(([pi_E_R]-[0.1947,	0.5151,	0.1989,	0.0785,	0.0129]).^2);  
    

Dist_EducGroups_U = sum(([pi_E_U]-[0.0509,	0.2405,	0.3044,	0.2829,	0.1212]).^2);  
        
%% Workers and Production

Dist_WnP = Dist_VA + Dist_Emp;
%% Population
Dist_Pop = Dist_pop_2010;

%% Education
Dist_EducGroups = Dist_EducGroups_R + Dist_EducGroups_U;

%% Total
Dist_Total = Dist_EducGroups + Dist_Pop + Dist_WnP;

f= 100*Dist_Pop+Dist_VA + Dist_Emp;